package com.example.demo.newtouch_ai.baidu;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.baidu.aip.face.AipFace;
import com.baidu.aip.face.MatchRequest;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.Map;

/**
 * @program: demo_sb
 * @description:
 * @author: luojm
 * @create: 2018-09-27 12:21
 */
public class test {
    public static Object sample(AipFace client) throws JSONException {
        String filePath = "C:\\Users\\luojm\\Desktop\\20180828040121699.jpeg";
        File imgData = new File(filePath);
        String imgStr = Base64.encode(imgData);

        String filePath2 = "C:\\Users\\luojm\\Desktop\\359b033b5bb5c9eae7b06f76d939b6003bf3b3e0.jpg";
        File imgData2 = new File(filePath2);
        String imgStr2 = Base64.encode(imgData2);


        String image1 = "C:\\Users\\luojm\\Desktop\\3.jpeg";
        String image2 = "C:\\Users\\luojm\\Desktop\\2.jpg";

        // image1/image2也可以为url或facetoken, 相应的imageType参数需要与之对应。
        MatchRequest req1 = new MatchRequest(imgStr, "BASE64");
        MatchRequest req2 = new MatchRequest(imgStr2, "BASE64");
        ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
        requests.add(req1);
        requests.add(req2);

        JSONObject res = client.match(requests);
//        Object score = JSON.parseObject(res.get("result").toString()).get("score");
//        System.err.println("score="+score);
//        System.out.println(res.toString(2));
        Map mapType = JSON.parseObject(res.toString(), Map.class);
        for (Object obj : mapType.keySet()) {
            System.out.println("key为：" + obj + "值为：" + mapType.get(obj));
        }

        return res;

    }

    public static AipFace getAipFace() {
        //设置APPID/AK/SK
        String APP_ID = "14296020";
        String API_KEY = "9UacVm9uxgxbvWGesrkAyL4w";
        String SECRET_KEY = "WCmMAizoHZmmPQDj9N8Dh5vuUsakP1fl";
        return new AipFace(APP_ID, API_KEY, SECRET_KEY);
    }

//    public static void main(String[] args) throws JSONException {
//        AipFace aipFace = getAipFace();
//        Object sample = sample(aipFace);
//        System.err.println(sample);
//    }

    public static void main(String[] args) {
        String s = "11.67";
        float i = Float.parseFloat(s)/100;
        System.err.println(i);
    }
}
